import Page
from Page import Map
from Base.Base import Base
from selenium.webdriver.common.by import By


class MapSearchResultPage(Base):
    """
    搜索结果页面

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.result_home_btn = (By.XPATH, Map.RESOURCE_ID.format("rl_navigation_home"))

        # 左侧的返回键
        self.result_back_btn = (By.XPATH, Map.RESOURCE_ID.format('rl_navigation_back'))

        # 当前定位
        self.result_positioning_text = (By.XPATH, Map.RESOURCE_ID.format("search_city"))

        # 搜索框
        self.result_bar_input = (By.XPATH, Map.RESOURCE_ID.format("et_field"))

        # 删除按钮
        self.result_delete_btn = (By.XPATH, Map.RESOURCE_ID.format("delete_field"))

        # 搜索按钮
        self.result_search_btn = (By.XPATH, Map.RESOURCE_ID.format("search_button"))

        # 搜索按钮
        self.result_search_btn = (By.XPATH, Map.RESOURCE_ID.format("search_button"))

        # 导航图标
        self.result_navigation_icon = (By.XPATH, Map.navigation_icon.format(""))

        # 导航地址
        self.result_navigation_address_text = (By.XPATH, Map.navigation_address_text.format(""))

        # 导航城市地址
        self.result_navigation_city_address_text = (By.XPATH, Map.navigation_city_address_text.format(""))

        # 立即导航图标
        self.result_navigation_now_icon = (By.XPATH, Map.navigation_now_icon.format(""))
        # self.result_navigation_now_icon = (By.XPATH, Map.RESOURCE_ID.format("btn_go_here"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None

        """
        self.click_element(self.result_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.result_back_btn)

    def get_positioning(self):
        """
        获取当前定位

        :return:获取元素
        """
        return self.find_element_o(self.result_positioning_text)

    def input_bar(self, index):
        """
        搜索框输入内容

        index 为默认输入内容
        :return:输入内容
        """
        self.input_text(self.result_bar_input, text=index)

    def click_delete(self):
        """
        点击删除按钮

        :return:None
        """
        self.click_element(self.result_delete_btn)

    def click_search(self):
        """
        点击搜索按钮

        :return:None
        """
        self.click_element(self.result_search_btn)

    def get_navigation(self, index=1):
        """
        获取搜索图标

        index 为结果选择条数.默认选择第一条
        :return:获取元素
        """
        self.result_navigation_icon = (By.XPATH, Map.navigation_icon.format(index))
        return self.find_element_o(self.result_navigation_icon)

    def get_navigation_address(self, index=1):
        """
        获取地址文案

        index 为结果选择条数.默认选择第一条
        :return:获取元素
        """
        self.result_navigation_address_text = (By.XPATH, Map.navigation_address_text.format(index))
        return self.find_element_o(self.result_navigation_address_text)

    def get_navigation_city_address(self, index=1):
        """
        获取城市地址文案

        index 为结果选择条数.默认选择第一条
        :return:获取元素
        """
        self.result_navigation_city_address_text = (By.XPATH, Map.navigation_address_text.format(index))
        return self.find_element_o(self.result_navigation_city_address_text)

    def click_navigation_now(self, index=1):
        """
        点击立即导航按钮

        index 为结果选择条数.默认选择第一条
        :return:获取元素
        """
        self.result_navigation_now_icon = (By.XPATH, Map.navigation_now_icon.format(index))
        self.click_element(self.result_navigation_now_icon)

    def is_display_map_result(self):
        """
        查看是否进入地图搜索结果页

        :return:
        """
        return self.is_display(self.result_search_btn)
